package com.example.bean;

import lombok.Data;
import lombok.ToString;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

import static com.example.spring_xx_u_market.SpringXxUMarketApplication.jdbcTemplate;

@Data
@ToString
public class GoodsBriefV {
    private int goodsId;
    private String name;
    private String image_urls;
    private int type;
    private String detail_info;
    private double low;
    private double high;
    private String during_time;
    private String currency_type;

    public static List<GoodsBriefV> getGBVList(int account) {
        List<GoodsBriefV> query = jdbcTemplate.query("select goods_id, name,image_urls,type,detail_info,low,high,during_time,currency_type from second_hand.goods_info,second_hand.price_info where account = ? and price_id = goods_info.price_info_id",
                new BeanPropertyRowMapper<>(GoodsBriefV.class), account);
        if (query.size() == 0) {
            return null;
        } else {
            return query;
        }
    }

    public static List<GoodsBriefV> getGBVList(int size, int goods_number) {
        List<GoodsBriefV> query = jdbcTemplate.query("select goods_id, name,image_urls,type,detail_info,low,high,during_time,currency_type from second_hand.goods_info,second_hand.price_info where price_id = goods_info.price_info_id limit ?,?",
                new BeanPropertyRowMapper<>(GoodsBriefV.class), goods_number, size + goods_number);
        if (query.size() == 0) {
            return null;
        } else {
            return query;
        }
    }
}